<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="活动细类名称">
          <a-input placeholder="请输入活动细类名称" v-decorator="['categoriesDetailName',validatorRules.categoriesDetailName]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="活动方式">
          <cn-dict-select-tag
            placeholder="请选择活动方式"
            dict-code="act_method"
            triggerChange
            :options="{value:'dictDataCode',label:'dictDataDesc'}"
            v-decorator.trim="[ 'actMethodCode', validatorRules.actMethodCode]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否核销">
          <cn-dict-select-tag  v-decorator="['isAudit', {initialValue:'1'}]" placeholder="请选择是否核销"
                              :type="'radio'" :triggerChange="true" dictCode="yesOrNo"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="超额核销比例%">
          <a-input-number v-decorator="[ 'extraAuditRatio', validatorRules.extraAuditRatio]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="核销有效期(月)">
          <a-input-number v-decorator="[ 'auditValidity', validatorRules.auditValidity]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否推送SFA">
          <cn-dict-select-tag  v-decorator="['isPushSfa', {initialValue:'0'}]" placeholder="请选择是否推送SFA"
                              :type="'radio'" :triggerChange="true" dictCode="yesOrNo"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否允许多次核销">
          <cn-dict-select-tag  v-decorator="['isMultipleAudit', {initialValue:'0'}]" placeholder="是否允许多次核销"
                              :type="'radio'" :triggerChange="true" dictCode="yesOrNo"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否控制门店金额">
          <cn-dict-select-tag  v-decorator="['isControlTer', {initialValue:'0'}]" placeholder="是否控制门店金额"
                              :type="'radio'" :triggerChange="true" dictCode="yesOrNo"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="支付方式">
          <j-multi-select-tag v-decorator="['payType', validatorRules.payType]" placeholder="请选择支付方式"
                             :type="'checkbox'" :triggerChange="true" dictCode="pay_type"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="活动发布需求">
          <a-input placeholder="请输入活动发布需求" v-decorator="['actReleaseNeed', validatorRules.actReleaseNeed]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="活动数据采集要求">
          <j-multi-select-tag v-decorator="['actCollectNeet', validatorRules.actCollectNeet]" placeholder="请选择活动数据采集要求"
                              :type="'checkbox'" :triggerChange="true" dictCode="act_collect_neet"/>

        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="超额核销控制">
          <j-multi-select-tag v-decorator="['aboveAudit', validatorRules.aboveAudit]" placeholder="请选超额核销控制"
                             :type="'checkbox'" :triggerChange="true" dictCode="above_audit"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="预算科目">
          <j-select-subjects placeholder="请选择关联预算科目名称"
                             :multiple="false" v-decorator="['subjectsCode', validatorRules.subjectsCode]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-textarea placeholder="请输入备注" v-decorator="['remarks', {}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JMultiSelectTag from '../../../../components/dict/JMultiSelectTag'
  import JSelectCategories from '../../../../components/cn-select-popup/JSelectCategories'
  import JSelectSubjects from '@/components/cn-select-popup/JSelectSubjects'
  export default {
    name: "TpmActCategoriesDetailModal",
    components: { JMultiSelectTag, JSelectCategories,JSelectSubjects },
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          categoriesDetailName:{rules: [{ required: true, message: '请输入活动细类名称!' }]},
          // extraAuditRatio:{rules: [{ required: true, message: '请确定超额核销比例%!' }]},
          // auditValidity:{rules: [{ required: true, message: '请确定核销有效期(月)!' }]},
          payType:{rules: [{ required: true, message: '请选择支付方式!' }]},
          actMethodCode:{rules: [{ required: true, message: '请选择活动方式!' }]},
          // actReleaseNeed:{rules: [{ required: true, message: '请输入活动发布需求!' }]},
          actCollectNeet:{rules: [{ required: true, message: '请选择活动数据采集要求!' }]},
          // aboveAudit:{rules: [{ required: true, message: '请选超额核销控制!' }]},
          subjectsCode:{rules: [{ required: true, message: '请选择关联预算科目名称!' }]},
        },
        url: {
          add:window._CONFIG['domianTpmURL']+ "/act/tpmActCategoriesDetail/saveOrUpdate",
          edit:window._CONFIG['domianTpmURL']+ "/act/tpmActCategoriesDetail/saveOrUpdate",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'remarks','categoriesDetailCode','categoriesDetailName','actMethodCode','actMethodName','isAudit','extraAuditRatio','auditValidity','isPushSfa','isMultipleAudit','isControlTer','payType','actReleaseNeed','actCollectNeet','aboveAudit','categoriesCode','categoriesName','subjectsCode','subjectsName'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
              httpurl+=this.url.add;
              method = 'post';

            let formData = Object.assign(this.model, values);
            //时间格式化

            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>